package com.example.backend.controller;

import com.example.backend.common.ResultMessage;
import com.example.backend.entity.PingJia;
import com.example.backend.service.IPingJiaService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 评价控制类
 */
@RestController
@RequestMapping("/pingjia")
public class PingJiaController {
    @Autowired
    private IPingJiaService pingJiaService;
    @PostMapping
    public ResultMessage addPingJia(@RequestBody PingJia pingJia) {
        if(pingJiaService.addPingJia(pingJia)){
            return ResultMessage.success(null,"评价成功");
        }
        return ResultMessage.error("评价失败");
    }

    @DeleteMapping("/{pjid}")
    public ResultMessage deletePingJia(@PathVariable Integer pjid) {
        if(pingJiaService.deletePingJia(pjid)){
            return ResultMessage.success(null,"删除成功");
        }
        return ResultMessage.error("删除失败");
    }

    @PutMapping
    public ResultMessage updatePingJia(@RequestBody PingJia pingJia) {
        if(pingJiaService.updatePingJia(pingJia)){
            return ResultMessage.success(null,"评价成功");
        }
        return ResultMessage.error("评价失败");
    }

    @GetMapping("/{pjid}")
    public ResultMessage queryPingJia(@PathVariable Integer pjid) {
        return ResultMessage.success(pingJiaService.queryPingJia(pjid),"查询成功");
    }

    @GetMapping
    public ResultMessage queryPingJiaList() {
        return ResultMessage.success(pingJiaService.queryPingJiaList(),"查询成功");
    }
    @GetMapping("/sjpj/{sjid}")
    public ResultMessage getAVGPinFen(@PathVariable Integer sjid) {
        return ResultMessage.success(pingJiaService.getAVGPinFen(sjid),"查询成功");
    }

    @GetMapping("/allpj/{sjid}")
    public ResultMessage getPinJias(@PathVariable Integer sjid) {
        return ResultMessage.success(pingJiaService.getPinJias(sjid),"查询成功");
    }

    @GetMapping("/allpj")
    public ResultMessage getAllPingJiaAnalysis() {
        return ResultMessage.success(pingJiaService.getAllPingJiaAnalysis(),"查询成功");
    }

    @GetMapping("/userpj/{sjid}")
    public ResultMessage getSJPingJiaAnalysis(@PathVariable Integer sjid) {
        return ResultMessage.success(pingJiaService.getSJPingJiaAnalysis(sjid),"查询成功");
    }

    @GetMapping("/users/{yhid}")
    public ResultMessage queryPingJiaByYhid(@PathVariable Integer yhid) {
        return ResultMessage.success(pingJiaService.queryPingJiaByYhid(yhid),"查询成功");
    }

    @GetMapping("/sjplq/{sjid}")
    public ResultMessage getSJPLQ(@PathVariable Integer sjid) {
        return ResultMessage.success(pingJiaService.getSJPLQ(sjid),"查询成功");
    }
}
